package sk.isomi.jcf;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import sk.isomi.minihr.entities.Employee;

public class CollectionImpl {
	
	public static void main(String[] args) throws Exception {
		//testList();
		//testSet();
		testComparator();
	}
	
	private static void testComparator() throws Exception {
		List<Employee> employees = new LinkedList<Employee>();
		Set<Employee> employeesSet = new HashSet<Employee>();
		
		// init 		
		Employee empl1 = new Employee("E12", "Skulavik", "111111/1111", "jan.skulavik@openit.sk");
		Employee empl2 = new Employee("E13", "Kubicek",  "222222/2222", "jaro.kubicek@openit.sk");
		Employee empl3 = new Employee("E11", "Skulavik", "111111/1111", "jan.skulavik@openit.sk");
		
		employees.add(empl1);
		employees.add(empl2);
		employees.add(empl3);		
		employeesSet.add(empl1);
		employeesSet.add(empl2);
		employeesSet.add(empl3);		
		
		//class Collections
		List<Employee> sortedSet = new LinkedList<Employee>(employeesSet);
		Collections.sort(sortedSet, new CompareEmployeeById(CompareEmployeeById.DESC));

		
		Collections.sort(employees, new CompareEmployeeById(CompareEmployeeById.DESC));

		Collections.sort(employees, new Comparator<Employee>() {
			@Override
			public int compare(Employee o1, Employee o2) {
				return o1.getId().compareTo(o2.getId());
			}			
		});

		for (Employee employee : sortedSet) {
			System.out.println(employee);
		}
	}

	public static void testList() throws Exception {
		List<Employee> employees = new LinkedList<Employee>();
		
		// init 		
		Employee empl1 = new Employee("E11", "Skulavik", "111111/1111", "jan.skulavik@openit.sk");
		Employee empl2 = new Employee("E12", "Kubicek",  "222222/2222", "jaro.kubicek@openit.sk");
		Employee empl3 = new Employee("E11", "Skulavik", "111111/1111", "jan.skulavik@openit.sk");
		
	
		employees.add(empl1);
		employees.add(empl2);
		employees.add(empl3);
		
		System.out.println(employees.size());
		
		for (Employee employee : employees) {
			System.out.println(employee);
		}
			
		employees.remove(empl3);
		
		for (int i = 0; i < employees.size(); i++) {
			System.out.println(employees.get(i));
		}		
	}

	public static void testSet() throws Exception {
		Set<Employee> employeesHS = new HashSet<Employee>();
		Set<Employee> employeesTS = new TreeSet<Employee>();
		Set<Employee> employeesLHS = new LinkedHashSet<Employee>();
				
		// init 		
		Employee empl1 = new Employee("E11", "Skulavik", "111111/1111", "jan.skulavik@openit.sk");
		Employee empl2 = new Employee("E12", "Kubicek",  "222222/2222", "jaro.kubicek@openit.sk");
		Employee empl3 = new Employee("E13", "Skulavik", "111111/1111", "jan.skulavik@openit.sk");
			
		employeesHS.add(empl1);
		employeesHS.add(empl2);
		employeesHS.add(empl3);
		
		System.out.println("HS" + employeesHS.size());
		
		for (Employee employee : employeesHS) {
			System.out.println(employee);
		}	
		
		// TreeSet ----------------------------------------------- 
		employeesTS.add(empl1);
		employeesTS.add(empl2);
		employeesTS.add(empl3);

		System.out.println("TS" + employeesTS.size());
		
		for (Employee employee : employeesTS) {
			System.out.println(employee);
		}	

		// LinkedHashSet ----------------------------------------------- 
		employeesLHS.add(empl1);
		employeesLHS.add(empl2);
		employeesLHS.add(empl3);

		System.out.println("LHS" + employeesLHS.size());
		
		for (Employee employee : employeesLHS) {
			System.out.println(employee);
		}	

	}

}
